home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / talinasm.lha / hashval.asm < prev    next >
Encoding:
Assembly Source File  |  1992-04-11  |  2.1 KB  |  76 lines

  1. *==========================================================================*
  2. *  ReverseList.asm -- Reverses the order of a singly-linked list           *
  3. *  By Talin. (c) 1990 Sylvan Technical Arts.                               *
  4. *==========================================================================*
  5.  
  6.             xdef        _HashVal
  7.             xdef        _CmpMemI
  8.  
  9. _HashVal:            ; (name:a0, length:d0, hashsize:d1)
  10.             movem.l        d2/d3,-(sp)
  11.             moveq        #0,d3                    ; clear initial hash value
  12.             moveq        #0,d2                    ; clear upper half of character value
  13.             bra.s        2$
  14. 1$            move.b        (a0)+,d2                ; next byte of string
  15.             and.b        #%11011111,d2            ; munge byte so upper case == lower.
  16.             mulu        #13,d3                    ; multiply hash *13.
  17.             add.l        d2,d3                    ; add new byte to hashval.
  18. 2$            dbra        d0,1$                    ; loop until done
  19.             swap        d3                        ; clear upper half d3
  20.             clr.w        d3                        ;    to avoid divide overflow
  21.             swap        d3
  22.             divu.w        d1,d3                    ; divide by hash table size.
  23.             clr.w        d3                        ; get rid of quotient
  24.             swap        d3                        ; get just remainder
  25.             move.l        d3,d0                    ; return hash value
  26.             movem.l        (sp)+,d2/d3
  27.             rts
  28.  
  29.  
  30. ; IMATCH - a macro that quickly does a case-insensitive character test
  31. ;    Note this function destroys the two registers passed to it.
  32. ;    Usage:
  33. ;            IMATCH        reg1,reg1,matchlabel,nomatchmabel
  34.  
  35. IMATCH        macro
  36.  
  37.             cmp.b        \1,\2                    ; if characters match
  38.             beq.s        \3
  39.             eor.b        \1,\2                    ; get exclusive or of characters
  40.             cmp.b        #32,\2                    ; if different only by bit 32
  41.             bne.s        \4                        ; then
  42.             bset        #5,\1                    ; force to upper case
  43.             cmp.b        #$61,\1                    ; if less than lower case 'a'
  44.             blo.s        \4                        ; then no match
  45.             cmp.b        #$7a,\1                    ; if less that or equal to lower 'z'
  46.             bls.s        \3                        ; then match
  47.             cmp.b        #$E0,\1                    ; if less than lower case 'à'
  48.             blo.s        \4                        ; then no match
  49.             bra.s        \3                        ; then match
  50.  
  51.             endm
  52.  
  53. _CmpMemI
  54.             move.l    4(sp),a0
  55.             move.l    8(sp),a1
  56.             move.l    12(sp),d1
  57.             move.l    d2,-(sp)
  58.             bra.s    3$
  59.  
  60. 2$            move.b    (a1)+,d0        ; are current bytes different?
  61.             move.b    (a0)+,d2
  62.  
  63.             IMATCH    d0,d2,3$,1$
  64.  
  65. 3$            dbra    d1,2$
  66.  
  67.             moveq    #1,d0
  68.             move.l    (sp)+,d2
  69.             rts
  70.  
  71. 1$            moveq    #0,d0
  72.             move.l    (sp)+,d2
  73.             rts
  74.  
  75.             end
  76.